from django.db import models
from employee.models import EmpDepartment


# Create your models here.
class AdminRoles(models.Model):
    role = models.CharField(max_length=50, default='', verbose_name='角色')
    role_name = models.CharField(max_length=50, default='', verbose_name='角色名称')
    is_used = models.BooleanField(verbose_name='是否启用', default=True)
    introduction = models.CharField(max_length=255, default='', verbose_name='简介')
    parent = models.ForeignKey('self', blank=True, null=True, on_delete=models.DO_NOTHING, verbose_name='上级角色')
    create_time = models.DateTimeField(blank=True, null=True, auto_now_add=True, editable=True, verbose_name='创建时间')
    modify_time = models.DateTimeField(blank=True, null=True, auto_now=True, editable=True, verbose_name='修改时间')

    def __str__(self):
        return self.role_name

    class Meta:
        managed = True
        db_table = 'admin_roles'
        verbose_name_plural = '管理员平台用户角色表'
        verbose_name = '管理员平台用户角色表'


class AdminUser(models.Model):
    username = models.CharField(max_length=50, default='', verbose_name='用户名')
    password = models.CharField(max_length=255, default='', verbose_name='登录密码')
    account = models.CharField(max_length=255, default='', verbose_name='账户')
    avatar = models.CharField(max_length=255, default='', verbose_name='头像')
    introduction = models.CharField(max_length=255, default='', verbose_name='简介')
    is_superuser = models.BooleanField(verbose_name='是否是管理员', default=False)
    is_used = models.BooleanField(verbose_name='是否启用', default=True)
    roles = models.ManyToManyField(AdminRoles, verbose_name='角色')
    department = models.ManyToManyField(EmpDepartment, verbose_name='管辖部门')
    xft_account = models.ForeignKey(to='xftinterfaces.XftAccount', on_delete=models.SET_NULL, null=True, blank=True, verbose_name='薪福通账户', related_name='xft_account', db_constraint=False)
    create_time = models.DateTimeField(blank=True, null=True, auto_now_add=True, editable=True, verbose_name='创建时间')
    modify_time = models.DateTimeField(blank=True, null=True, auto_now=True, editable=True, verbose_name='修改时间')

    def __str__(self):
        return self.account

    class Meta:
        managed = True
        db_table = 'admin_user'
        verbose_name_plural = '管理员平台用户表'
        verbose_name = '管理员平台用户表'
